﻿using System.Collections.Generic;
using System;
using System.Windows;
using SUNRPA.CONTROLS.IMPL.domain;
using SUNRPA.CONTROLS.IMPL.domain.flowItemParam;
using SUNRPA.CONTROLS.IMPL.util;
using RPAVIEW.util;
using SUNRPA.CONTROLS.IMPL.domain.constant;
using SUNRPA.CONTROLS.IMPL.interfaces;
using System.Collections.Concurrent;
using SUNRPA.CONTROLS.IMPL.domain.flowRunningVar;

namespace RPAVIEW.views.EditPage.flows.OpenInputDiaN {
    /// <summary>
    /// UserInputDialog.xaml 的交互逻辑
    /// </summary>
    public partial class UserInputDialog:Window,IDelegateInterface {
        private OpenInputDiaNParam? param; 
        private ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>>? golbaldata;
        public UserInputDialog() {
            InitializeComponent();
        }

        private void SaveInput(object sender, RoutedEventArgs e) {
            this.saveVar(this.golbaldata, param.OutVarName, new StringModel(param.OutVarName, this.inputContent.Text), DefaultContents.RUNNING_PARAM);
            this.Close();
        }

        public void DelegateMethod(FlowItem item, ConcurrentDictionary<string, ConcurrentDictionary<string, RPAVariableDefineWrapper>> golbaldata) {
            try{ 
                UserInputDialog dialog = new UserInputDialog();
                dialog.param = item.ControlParam as OpenInputDiaNParam;
                dialog.golbaldata = golbaldata;
                string title = dialog.param.DialogTitle;
                this.GetStringVar(ref title, golbaldata);
                dialog.Title = title;
                dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                User32Utils.SetForegroundWindow(ElementUtil.getWindowPtr(dialog));
                dialog.Activate();
                dialog.Topmost = true;
                dialog.ShowDialog();
            }catch (Exception ex){ 
                throw new RpaRuntimeException($"创建用户输入对话框出错:{ex.StackTrace}");
            }
        }
    }
}
